package com.woniuxy.exception;

import com.woniuxy.demo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


@RestControllerAdvice
@Slf4j
public class WoniuExceptionHandler {


    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e) {
//        e.printStackTrace();
        log.error("出现异常", e);
        return new Result().setCode(500).setMsg(e.getMessage());
    }


    @ExceptionHandler(AccessDeniedException.class)
    public Result handlerAccessDeniedException(AccessDeniedException e) {
//        e.printStackTrace();
        log.error("出现异常", e);
        return new Result().setCode(403).setMsg(e.getMessage());
    }

    @ExceptionHandler(WoniuException.class)
    public Result exceptionWoniuHandler(WoniuException e) {
//        e.printStackTrace();
        log.error("出现异常", e);
        return new Result().setCode(e.getCode()).setMsg(e.getMessage());
    }
}
